<template>
    <div class="commer-body">
        <div class="container">
            <!-- left列表 -->
            <div class="body-left">
                <ul>
                    <div class="title">
                        <div class="nav">
                            <div class="main">快速导航</div>
                            <div class="main-es">Quick navigation</div>
                        </div>
                    </div>
                    <li>
                        <span>院部简介</span>
                        <span class="span">
                            <hr>
                        </span>
                    </li>
                </ul>
            </div>

            <div class="body-right">
                <div class="body-nav">
                    <div class="nav-left">
                        <span>院部简介</span>
                    </div>
                    <div class="nav-right">
                        <span>当前所在位置：</span>
                        <a href="index.html">首页</a>
                        <a href="shiziduiwu.html">院部简介</a>
                        <input type="text" placeholder="输入关键词搜索">
                        <img src="../../assets/搜索.png" alt="">
                    </div>
                </div>
                <div class="title">
                    <span class="one"></span>
                    <span class="two"></span>
                    <span class="three"></span>
                </div>
                <div class="body-one">
                    <div class="container-one">
                        <div class="one-item" v-for="(item, index) in newsItems" :key="index">
                            <span class="icon">·</span>
                            <span class="text">{{ item.text }}</span>
                            <span class="year">{{ item.year }}</span>
                        </div>
                    </div>
                </div>
                <div class="body-two">
                    <div class="container-two">
                        <div class="two-item" v-for="(item, index) in newsData" :key="index">
                            <div class="two-left">
                                <img :src="item.imageUrl" alt="News Image">
                            </div>
                            <div :class="['two-right', item.classModifier]">
                                <p>{{ item.title }}</p>
                                <p v-if="item.hasOwnProperty('additionalText')" class="none">{{ item.additionalText }}
                                </p>
                                <span>{{ item.date }}</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="body-three">
                    <div class="container-three">
                        <div class="three-item" v-for="(item, index) in items" :key="index">
                            <div class="three-img">
                                <img :src="item.imageUrl" alt="Image description">
                            </div>
                            <div class="three-text">{{ item.text }}</div>
                            <hr>
                            <div class="three-footer">
                                <span>{{ item.date }}</span>
                            </div>
                        </div>
                    </div>
                </div>
                <a href="#" class="a">查看更多</a>
            </div>
        </div>
    </div>
</template>

<script>
import $ from 'jquery';
import { ref, reactive } from 'vue';
// 师资队伍面包屑点击切换内容
$(document).ready(function () {
    $('.title .one').on('click', function () {
        // 切换.body-three和.body-one的显示状态
        $('.body-three').hide();    // 隐藏
        $('.body-one').show();      // 显示
        $('.body-two').hide();      // 隐藏
        // 更换.one的背景图片
        $('.two').css('background-image', 'url(src/assets/two.png)'); // 替换为新的图片路径
        $('.three').css('background-image', 'url(src/assets/three.png)'); // 替换为新的图片路径
        // 更换.two的背景图片
        $('.one').css('background-image', 'url(src/assets/one-red.png)'); // 替换为新的图片路径
    });
    $('.title .two').on('click', function () {
        // 切换.body-three和.body-one的显示状态
        $('.body-three').hide();    // 隐藏
        $('.body-one').hide();      // 隐藏
        $('.body-two').show();      // 显示
        // 更换.one的背景图片
        $('.one').css('background-image', 'url(src/assets/one.png)'); // 替换为新的图片路径
        $('.three').css('background-image', 'url(src/assets/three.png)'); // 替换为新的图片路径
        // 更换.two的背景图片
        $('.two').css('background-image', 'url(src/assets/two-red.png)'); // 替换为新的图片路径
    });
    $('.title .three').on('click', function () {
        // 切换.body-three和.body-one的显示状态
        $('.body-three').show();    // 显示
        $('.body-one').hide();      // 隐藏
        $('.body-two').hide();      // 隐藏
        // 更换.one的背景图片
        $('.one').css('background-image', 'url(src/assets/one.png)'); // 替换为新的图片路径
        $('.two').css('background-image', 'url(src/assets/two.png)'); // 替换为新的图片路径
        // 更换.two的背景图片
        $('.three').css('background-image', 'url(src/assets/three-red.png)'); // 替换为新的图片路径
    });
})

export default {
  setup() {
    // 使用 reactive 创建响应式数据对象
    const newsItems = reactive(Array.from({ length: 6 }, () => ({
      text: '山东城院召开公文写作培训会', 
      year: '2022-11-24'
    })));

    const newsData = reactive([
      {
        imageUrl: 'src/assets/3.png',
        title: '传承八一精神 凝聚奋进力量|马克思主义学院第一-第二党支部开展主题活动',
        date: '2021-05-21',
      },
      {
        imageUrl: 'src/assets/3.png',
        title: '传承八一精神 凝聚奋进力量|马克思主义学院第一-第二党支部开展主题活动',
        additionalText: '新生开展“红色观影”德育课…',
        date: '2021-05-21',
        classModifier: 'two-right1',
      },
      {
        imageUrl: 'src/assets/3.png',
        title: '传承八一精神 凝聚奋进力量|马克思主义学院第一-第二党支部开展主题活动',
        date: '2021-05-21',
        classModifier: 'two-right2',
      },
      {
        imageUrl: 'src/assets/3.png',
        title: '传承八一精神 凝聚奋进力量|马克思主义学院第一-第二党支部开展主题活动',
        date: '2021-05-21',
        classModifier: 'two-right3',
      },
    ]);

    const items = reactive(Array.from({ length: 4 }, () => ({
      imageUrl: 'src/assets/3.png',
      text: '传承八一精神 凝聚奋进力量|马克思主义学院第一党支部开展主题活动',
      date: '2021-04-17'
    })));

    // 返回需要在模板中使用的数据
    return {
      newsItems,
      newsData,
      items,
    };
  },
};
</script>

<style scoped lang="scss">
.commer-body {
    @media (max-width: 475px) {
        padding: 0;
        margin-top: 80px;
        padding-bottom: 20px;
    }

    margin-top: 300px;
    padding-bottom: 200px;
    width: 100%;
    background-color: #fbfbfd;

    .container {
        @media (max-width: 475px) {
            width: 90%;
        }

        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        width: 80%;
        margin: 0 auto;

        .body-left {
            @media (max-width: 475px) {
                display: none;
            }

            padding-bottom: 20px;
            width: 16%;
            border-radius: 0 0 10px 10px;

            ul {
                position: -webkit-sticky;
                /* 对于Safari的支持 */
                position: sticky;
                top: 100px;
                /* 页面滚动多少像素后开始固定 */
                z-index: 1000;
                /* 确保元素在滚动时位于最上层 */
                /* 其他样式保持不变 */
                width: 100%;

                .title {
                    position: absolute;
                    top: -100px;
                    width: 100%;
                    height: 100px;
                    color: #fff;
                    text-align: center;
                    border-radius: 10px 10px 0 0;
                    background-color: #005bac;

                    .nav {
                        height: 100%;
                        display: flex;
                        flex-direction: column;
                        align-content: center;
                        justify-content: center;
                        align-items: center;

                        .main {
                            width: 100%;
                            font-size: 24px;
                        }

                        .main-es {
                            width: 100%;
                            font-size: 12px;

                        }
                    }
                }

                li {
                    border-top: 2px solid #dcdcdc;
                    width: 100%;
                    height: 52px;
                    font-size: 18px;
                    line-height: 52px;
                    background-color: #fff;

                    span {
                        display: block;
                        width: 100%;
                        height: 100%;
                        color: #0a61af;
                        text-align: center;
                    }

                    .span {
                        width: 100%;
                        height: 40%;
                        background-color: #fff;
                        border-radius: 0 0 10px 10px;

                        hr {
                            width: 90%;
                            margin: 0 auto;
                        }
                    }
                }

                .index {
                    background-position: 100% 50%;
                    background-size: 40px;
                    background-repeat: no-repeat;
                    background-image: url(../../assets/right.png);
                    background-color: #f7f7f7;
                }
            }

        }

        .body-right {
            @media (max-width: 475px) {
                width: 100%;
                border: none;
            }

            padding: 10px 0 0;
            width: 76%;
            background-color: #fff;
            border: 2px solid #dfe0e0;

            .body-nav {
                display: flex;
                flex-wrap: wrap;
                align-items: center;
                justify-content: space-between;
                border-bottom: 2px solid #f1f1f1;
                width: 100%;
                height: 40px;

                .nav-left {
                    @media (max-width: 475px) {
                        width: 30%;
                    }

                    color: #0b62af;
                    width: 12%;
                    height: 100%;
                    background-image: url(../../assets/11.png);
                    background-repeat: no-repeat;
                    background-position: 34% 20%;
                    background-size: 14px;

                    span {
                        display: block;
                        width: 100%;
                        text-align: right;
                        font-weight: 600;
                    }
                }

                .nav-right {
                    @media (max-width: 475px) {
                        width: 60%;
                    }

                    width: 40%;
                    height: 100%;
                    line-height: 24px;
                    font-size: 12px;
                    display: flex;

                    a {
                        color: #000;
                        margin-right: 20px;
                    }

                    input {
                        text-align: center;
                        border: none;
                        height: 20px;
                        box-shadow: 0 2px 2px 1px rgba(0, 0, 0, 0.3);
                        @media (max-width: 475px) {
                            display: none;
                        }
                    }

                    img {
                        width: 8%;
                        height: 28px;
                        @media (max-width: 475px) {
                            display: none;
                        }
                    }
                }
            }

            .title {
                justify-content: right;
                display: flex;
                width: 100%;
                height: 30px;

                span {
                    display: block;
                    width: 30px;
                    height: 30px;
                    background-repeat: no-repeat;
                    background-size: 20px;
                    background-position: 50% 50%;
                }

                .one {
                    background-image: url(../../assets/one-red.png);
                }

                .two {
                    background-image: url(../../assets/two.png);
                }

                .three {
                    background-image: url(../../assets/three.png);
                }
            }

            .body-one {
                width: 100%;
                display: block;

                .container-one {
                    display: flex;
                    flex-wrap: wrap;
                    width: 90%;
                    margin: 0 auto;

                    .one-item {
                        &:hover {
                            color: #c90000;

                            .year {
                                background-image: url(../../assets/one-red.png);
                            }
                        }

                        margin: 10px 0;
                        display: flex;
                        width: 100%;
                        height: 30px;

                        .icon {
                            width: 2%;
                            height: 100%;
                            line-height: 30px;
                            text-align: center;
                            font-weight: 600;

                            @media (max-width: 475px) {
                                width: 4%;
                            }
                        }

                        .text {
                            @media (max-width: 475px) {
                                width: 74%;
                            }

                            width: 76%;
                            height: 100%;
                            line-height: 30px;
                        }

                        .year {
                            @media (max-width: 475px) {
                                width: 30%;
                                background-position: 0% 50%;
                            }

                            width: 12%;
                            height: 100%;
                            line-height: 30px;
                            text-align: right;
                            font-size: 14px;
                            background-image: url(../../assets/one.png);
                            background-size: 14px;
                            background-repeat: no-repeat;
                            background-position: 14% 50%;
                        }
                    }
                }
            }

            .body-two {
                display: none;
                width: 100%;

                .container-two {
                    position: relative;
                    width: 90%;
                    margin: 0 auto;
                    display: flex;
                    flex-wrap: wrap;

                    @media (max-width: 475px) {
                        width: 100%;
                    }

                    .two-item {
                        margin: 30px 0;
                        display: flex;
                        width: 100%;
                        height: 180px;

                        @media (max-width: 475px) {
                            height: 120px;
                            margin: 10px auto;
                        }

                        .two-left {
                            width: 40%;
                            height: 100%;
                            margin-left: 20px;
                            img {
                                width: 100%;
                                height: 100%;
                            }
                        }

                        .two-right {
                            @media (max-width: 475px) {
                                height: 100px;
                                top: 3.2%;
                                font-size: 14px;
                            }

                            padding: 10px;
                            position: absolute;
                            left: 38%;
                            top: 4.2%;
                            background-color: #fff;
                            display: flex;
                            flex-wrap: wrap;
                            width: 56%;
                            font-size: 20px;
                            height: 160px;
                            background-image: url(../../assets/bgimg.png);
                            background-repeat: no-repeat;
                            background-position: 110% -120%;
                            background-size: 200px;
                            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2),
                            0 6px 20px 0 rgba(0, 0, 0, 0.19);

                            p {
                                display: block;
                                width: 100%;
                            }

                            span {
                                text-indent: 2em;
                                font-size: 14px;
                                background-repeat: no-repeat;
                                background-position: 10% 10%;
                                background-size: 14px;
                                background-image: url(../../assets/11.png);
                            }
                        }

                        .two-right1 {
                            @media (max-width: 475px) {
                                height: 100px;
                                top: 28.2%;
                                font-size: 14px;
                            }

                            padding: 10px;
                            position: absolute;
                            top: 29.2%;
                            left: 38%;
                            background-color: #fff;
                            display: flex;
                            flex-wrap: wrap;
                            width: 56%;
                            font-size: 20px;
                            height: 160px;
                            background-image: url(../../assets/bgimg.png);
                            background-repeat: no-repeat;
                            background-position: 110% -120%;
                            background-size: 200px;
                            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2),
                            0 6px 20px 0 rgba(0, 0, 0, 0.19);

                            p {
                                display: block;
                                width: 100%;

                                @media (max-width: 475px) {
                                    display: none;
                                }
                            }

                            .none {
                                display: none;

                                @media (max-width: 475px) {
                                    display: block;
                                }
                            }

                            span {
                                text-indent: 2em;
                                font-size: 14px;
                                background-repeat: no-repeat;
                                background-position: 10% 10%;
                                background-size: 14px;
                                background-image: url(../../assets/11.png);
                            }
                        }

                        .two-right2 {
                            @media (max-width: 475px) {
                                height: 100px;
                                top: 53.2%;
                                font-size: 14px;
                            }

                            padding: 10px;
                            position: absolute;
                            top: 54.2%;
                            left: 38%;
                            background-color: #fff;
                            display: flex;
                            flex-wrap: wrap;
                            width: 56%;
                            font-size: 20px;
                            height: 160px;
                            background-image: url(../../assets/bgimg.png);
                            background-repeat: no-repeat;
                            background-position: 110% -120%;
                            background-size: 200px;
                            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2),
                            0 6px 20px 0 rgba(0, 0, 0, 0.19);

                            p {
                                display: block;
                                width: 100%;
                            }

                            span {
                                text-indent: 2em;
                                font-size: 14px;
                                background-repeat: no-repeat;
                                background-position: 10% 10%;
                                background-size: 14px;
                                background-image: url(../../assets/11.png);
                            }
                        }

                        .two-right3 {
                            @media (max-width: 475px) {
                                height: 100px;
                                top: 78.2%;
                                font-size: 14px;
                            }

                            padding: 10px;
                            position: absolute;
                            top: 79.2%;
                            left: 38%;
                            background-color: #fff;
                            display: flex;
                            flex-wrap: wrap;
                            width: 56%;
                            font-size: 20px;
                            height: 160px;
                            background-image: url(../../assets/bgimg.png);
                            background-repeat: no-repeat;
                            background-position: 110% -120%;
                            background-size: 200px;
                            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2),
                            0 6px 20px 0 rgba(0, 0, 0, 0.19);

                            p {
                                display: block;
                                width: 100%;
                            }

                            span {
                                text-indent: 2em;
                                font-size: 14px;
                                background-repeat: no-repeat;
                                background-position: 10% 10%;
                                background-size: 14px;
                                background-image: url(../../assets/11.png);
                            }
                        }
                    }
                }
            }

            .body-three {
                display: none;
                width: 100%;

                .container-three {
                    display: flex;
                    flex-wrap: wrap;
                    justify-content: space-between;
                    width: 90%;
                    margin: 0 auto;

                    @media (max-width: 475px) {
                        height: 1200px;
                    }

                    .three-item {
                        @media (max-width: 475px) {
                            width: 90%;
                            margin: 10px auto;
                            background: none;
                            height: 280px;
                        }

                        margin: 10px 0;
                        padding-bottom: 20px;
                        width: 49%;
                        display: flex;
                        flex-wrap: wrap;
                        background-image: url(../../assets/bgimg.png);
                        background-repeat: no-repeat;
                        background-position: 110% 130%;
                        background-size: 140px;
                        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2),
                        0 6px 20px 0 rgba(0, 0, 0, 0.19);

                        .three-img {
                            width: 100%;
                            height: 220px;

                            @media (max-width: 475px) {
                                height: 160px;
                                margin: 0;
                            }

                            margin-bottom: 20px;

                            img {
                                width: 100%;
                                height: 100%;
                            }
                        }

                        .three-text {
                            width: 94%;
                            margin: 0 auto;
                        }

                        hr {
                            @media (max-width: 475px) {
                                height: 1px;
                                margin: 0 auto;
                            }

                            margin: 10px auto;
                            width: 90%;
                        }

                        .three-footer {
                            width: 94%;
                            margin: 0 auto;
                            text-align: right;
                            font-size: 12px;
                            background-image: url(../../assets/11.png);
                            background-repeat: no-repeat;
                            background-position: 82% 50%;

                            @media (max-width: 475px) {
                                background-position: 72% 10%;
                            }
                        }
                    }
                }
            }

            .a {
                margin-top: 180px;
                display: block;
                width: 100%;
                text-align: center;
                color: #ccc;
                background-image: url(../../assets/right.png);
                background-repeat: no-repeat;
                background-position: right 46% bottom 60%;
                background-size: 30px;

                @media (max-width: 475px) {
                    margin: 20px 0;
                    display: block;
                    text-align: left;
                    text-indent: 8em;
                    background-position: right 40% bottom 60%;
                }
            }
        }
    }
}
</style>